package com.whw.springboot.walk.controller;


import com.whw.springboot.walk.UseToken;
import com.whw.springboot.walk.entity.Apply;
import com.whw.springboot.walk.entity.Message;
import com.whw.springboot.walk.service.ApplyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Api(tags = "参加活动模块")
@RestController
@RequestMapping("/api/apply")
public class ApplyController {

    @Resource
    private ApplyService applyService;


    @ApiOperation(value = "报名活动 只需要活动Id和参用户的Id")
    @UseToken(level = 0)
    @PostMapping(value = "/join")
    public Message<?> insertApply(Apply apply){
        return applyService.addApply(apply);
    }

    @ApiOperation(value = "退出活动 只需要活动Id和用户的Id")
    @UseToken(level = 0)
    @DeleteMapping(value = "/exit")
    public Message<?>  exitApply(Apply apply){
        return applyService.deleteApplyByActIdAndUserId(apply);
    }

    @ApiOperation(value = "根据主键Id删除参加")
    @UseToken(level = 1)
    @DeleteMapping(value = "/delByApplyId")
    public Message<?> delApplyByApplyId(String applyId){
        return applyService.deleteApplyByPrimaryKey(applyId);
    }

    @ApiOperation(value = "根据活动Id，删除参加活动情况")
    @UseToken(level = 1)
    @DeleteMapping(value = "/delByActId")
    public Message<?> delApplyByActId(String actId){
        return applyService.deleteApplyByActId(actId);
    }

    @ApiOperation(value = "根据活动Id，查看参加活动情况")
    @UseToken(level = 0)
    @GetMapping(value = "/findByActId")
    public Message<List<Apply>> findApplyByActId(String actId){
        return applyService.selectAllApplyByActId(actId);
    }

    @ApiOperation(value = "查看所有的参加情况")
    @UseToken(level = 1)
    @GetMapping(value = "/all")
    public Message<List<Apply>> findAll(){
        return applyService.selectAllApply();
    }


    @ApiOperation(value = "根据用户Id，查看参加活动情况")
    @UseToken(level = 0)
    @GetMapping(value = "/findByUserId")
    public Message<List<Apply>> findApplyByUserId(String userId){
        return applyService.selectAllApplyByUserId(userId);
    }

    @ApiOperation(value = "根据参加活动Id，查看参加活动情况")
    @UseToken(level = 0)
    @GetMapping(value = "/findByApplyId")
    public Message<Apply> findApplyByApplyId(String applyId){
        return applyService.selectApplyByPrimaryKey(applyId);
    }


    @ApiOperation(value = "根据userID和活动Id查参加情况")
    @GetMapping(value = "/findByUserIdAndActId")
    @UseToken(level = 0)
    public Message<Apply> findApplyByUserIdAndActId(String actId,String userId){
        return applyService.selectApplyByUserIdAndActId(userId,actId);

    }




}
